package com.jmyd.sharding.controller;

import com.jmyd.sharding.base.dto.KeywordQueryDto;
import com.jmyd.sharding.base.vo.PageBean;
import com.jmyd.sharding.base.vo.Result;
import com.jmyd.sharding.constants.BaseUrlConstants;
import com.jmyd.sharding.domain.dto.SysUserDto;
import com.jmyd.sharding.domain.dto.SysUserUpdateDto;
import com.jmyd.sharding.domain.vo.SysUserVo;
import com.jmyd.sharding.service.ISysUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 系统用户相关接口文档
 *
 * @author samphin
 * @date 2024-6-18 11:11:07
 */
@RestController
@RequestMapping(value = BaseUrlConstants.BASE_ADMIN_USER_API_PREFIX)
public class SysUserController {
    @Resource
    private ISysUserService sysUserService;

    /**
     * 保存
     *
     * @param dto
     */
    @PostMapping
    public Result<Boolean> save(@RequestBody SysUserDto dto) {
        final boolean bl = this.sysUserService.save(dto);
        return new Result<>(bl);
    }

    /**
     * 修改
     *
     * @param dto
     */
    @PutMapping
    public Result<Boolean> updateById(@RequestBody SysUserUpdateDto dto) {
        final boolean bl = this.sysUserService.updateById(dto);
        return new Result<>(bl);
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> deleteById(@PathVariable Long id) {
        final boolean bl = this.sysUserService.deleteById(id);
        return new Result<>(bl);
    }

    /**
     * 查看分页列表
     */
    @GetMapping
    public Result<PageBean<SysUserVo>> paging(KeywordQueryDto queryDto) {
        final PageBean<SysUserVo> pageBean = this.sysUserService.paging(queryDto);
        return new Result<>(pageBean);
    }

    /**
     * 查看详情
     */
    @GetMapping("/{id}")
    public Result<SysUserVo> queryById(@PathVariable Long id) {
        final SysUserVo vo = this.sysUserService.queryDetail(id);
        return new Result<>(vo);
    }
}